// pages/home/main.js
import { formatNumber} from '../../utils/util.js'
import { request } from "../../request/index.js"
const pic1 = 'https://s1.ax1x.com/2020/10/22/BFgG0e.png'
 const pic2 = 'https://s1.ax1x.com/2020/10/22/BFgVw4.png'
 Component({
  properties: {
    swiperList:{
      type: Array,
      value: []
    },
    hour:{
      type: Number,
      value: 0
    },
    remaintime:{
      type: String,
      value: ''
    },
  },
  data: {
    // swiperList:[],
    lists: ["首页", "11.11热卖", "美妆", "个护清洁", "童装", "手机", "母婴", "电脑办公", "数码", "食品饮料","大家电","家居厨具", "小家电", "运动", "女鞋", "家装", "酒水", "图书","男鞋","腕表珠宝","女装"],
    curIndex:0,
    pullStatus:true,//下拉按钮改变状态
    scrollLeft:0,
    // hour: 0,
    // remaintime: '02.00.00',
    background: [pic1, pic2,pic1, pic2,pic1, pic2,pic1, pic2,pic1, pic2,pic1, pic2],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    tab:[
      {
        txt: '精选',
        desc:'猜你喜欢',
        id: 0,
        isActive: true
      },
      {
        txt: '自营',
        desc:'急速配送',
        id: 1,
        isActive: false
      },
      {
        txt: '海购',
        desc:'京东国际',
        id: 2,
        isActive: false
      },
      {
        txt: '特价',
        desc:'正品低价',
        id: 3,
        isActive: false
      },
    ],
    box:[
      {
        txt:'医疗器械',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/151757/8/2969/4730/5f8ead30Eab1144d3/9eb3d028d5cf1299.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'
      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'医疗器械',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/151757/8/2969/4730/5f8ead30Eab1144d3/9eb3d028d5cf1299.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'
      },
      {
        txt:'医疗器械',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/151757/8/2969/4730/5f8ead30Eab1144d3/9eb3d028d5cf1299.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      ,
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      ,
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      ,
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      ,
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      ,
      {
        txt:'电视影音',
        width:'190',
        size: 24,
        img:'https://m.360buyimg.com/mobilecms/s152x168_jfs/t1/149382/7/11174/4740/5f8ead62E8859d4ed/662c3ddbee634abd.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s160x160_jfs/t1/129404/35/14857/103597/5f86dbe0Ea114e1c4/08639d1859e1f333.jpg!q70.dpg.webp'

      },
      ,
      {
        txt:'全球保健',
        width:'150',
        size: 18,
        img:'https://m.360buyimg.com/mobilecms/s180x200_jfs/t1/130450/19/12967/4741/5f8ead52Efaf6099e/acf1d72f691738a2.png.webp',
        innerImg:'https://m.360buyimg.com/mobilecms/s120x120_jfs/t1/130535/3/11675/231762/5f80334bE7836daae/01e6b61ddfaf9071.jpg!q70.dpg.webp'
      },
      ,
      
    ]
  },
    onShareAppMessage() {
      return {
        title: 'swiper',
        path: 'page/component/pages/swiper/swiper'
      }
    },
  
    changeIndicatorDots() {
      this.setData({
        indicatorDots: !this.data.indicatorDots
      })
    },
  
    changeAutoplay() {
      this.setData({
        autoplay: !this.data.autoplay
      })
    },
  
    intervalChange(e) {
      this.setData({
        interval: e.detail.value
      })
    },
  
    durationChange(e) {
      this.setData({
        duration: e.detail.value
      })
    },
  
  // getTime(){
  //   let timeId=setInterval(() => {
  //     let time = new Date();
  //     let year = time.getFullYear();
  //     let month = time.getMonth();
  //     let day = time.getDate();
  //     let hour = time.getHours();
  //     hour = Math.floor(hour/2)*2;
  //     var time2 = new Date(year+'/'+(month+1)+'/'+day+' '+(hour+2)+':00')
  //     let des = time2.getTime()-time.getTime()
  //     let time3 = new Date(des)
  //     let remaintime = formatNumber(time3.getHours()-8)+':'+formatNumber(time3.getMinutes())+':'+formatNumber(time3.getSeconds())
  //     this.setData({
  //       hour,
  //       remaintime
  //     })
  //   }, 1000);
    
  // },
  handleTab(e){
    const {index} = e.detail;
    let {tab} = this.data;
    tab.forEach((v,i) => {i===index?v.isActive=true:v.isActive=false})
    this.setData({
      tab
    })
  },
  onLoad: function () {
      // this.getTime()
      // this.lunbo()
  },
  // lunbo(){
  //   request({url:"https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata"})
  //     .then(result=>{
  //       this.setData({
  //         swiperList:result.data.message
  //       })
  //     })
  // },
  changeCate:function(e){

    var curCateIndex=e.currentTarget.dataset.index;
    
    this.setData({
    
    curIndex: curCateIndex,
    
    pullStatus: true
    
    })
    
    
    },
    
    //箭头点击下方导航显示状态
    
    pullDown:function(){
    
    this.setData({
    
    pullStatus:!this.data.pullStatus
    
    })

    
    },
    
    //下拉导航点击对应的部分
    
    pullCate:function(e){
    
    var that=this;
    
    var curIndex = e.currentTarget.dataset.index;
    
    var scrollLeft1=0;
    
    scrollLeft1 = scrollLeft1 + 50*curIndex;
    
    that.setData({
    
    curIndex: e.currentTarget.dataset.index,
    
    pullStatus:true,
    
    scrollLeft: scrollLeft1
    
    })
    
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})